//
//  MQSearchBar.swift
//  MQCRM
//
//  Created by 许博 on 2017/5/1.
//  Copyright © 2017年 mechat. All rights reserved.
//  搜索栏

import UIKit

class MQSearchBar: UISearchBar {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    private func setupUI(){
//        let seachbar = UISearchBar(frame: CGRect(x: 0, y: 0, width: KScreenW, height: 44))
        placeholder = "搜索附近位置"
        barTintColor = UIColor.clearBlue
        
        setImage(#imageLiteral(resourceName: "icMagnifierWhite.png"), for: .search, state: .normal)
        setImage(#imageLiteral(resourceName: "btnSearchbarClear.png"), for: .clear, state: .normal)
        showsCancelButton = true
        
        let cancaelBtn = value(forKey: "cancelButton") as? UIButton
        
        cancaelBtn?.setTitle(" 取消", for: .normal)
        cancaelBtn?.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        cancaelBtn?.setTitleColor(UIColor.white, for: .normal)
        
        let searchField = value(forKey: "_searchField") as? UITextField
        searchField?.backgroundColor = UIColor.color(r: 27, g: 101, b: 224)
        searchField?.textColor = UIColor.white
        let searchFieldLabel = searchField?.value(forKey: "placeholderLabel") as? UILabel
        searchFieldLabel?.textColor = UIColor.white
        
        
    }
    
   
    
}
